package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.ContentDAO;
import entity.Content;

/**
 * Servlet implementation class ChangeArticleServlet
 */
@WebServlet("/ChangeArticleServlet")
public class ChangeArticleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private ContentDAO contentDAO = ContentDAO.getInstance();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChangeArticleServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8"); 
		response.setCharacterEncoding("UTF-8"); 
		String con = request.getParameter("editorValue");
		int content_id =Integer.parseInt(request.getParameter("content_id"));
		int article_id =Integer.parseInt(request.getParameter("article_id"));
		System.out.println("article_id"+article_id);
		Content content =  (Content) contentDAO.get(article_id);
		content.setContent(con);
		System.out.println("content:"+con);
		contentDAO.update(content);
		request.getRequestDispatcher("ManageServlet").forward(request, response);
	}



}
